package my.jieh.tips.swing.order;
import java.awt.*;
import javax.swing.*;

/**
 * <p>Title: Core Java Technologies Tech Tips</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2002</p>
 *
 * <p>Company: Blueimp</p>
 *
 * @author jieh
 * @version 1.0
 */
public class ZOrder {
  public ZOrder() {
  }

  public static void main(String args[]) {
    EventQueue.invokeLater(new Runnable() {
      public void run() {
        JFrame frame = new JFrame("Z-Order");
        frame.setDefaultCloseOperation(
            JFrame.EXIT_ON_CLOSE);
        JButton top = new JButton("Top");
        JButton middle = new JButton("Middle");
        JButton bottom = new JButton("Bottom");

        int x=25;
        int y=50;
        int width=100;
        int height=50;
        int overlap = 25;
        int widthDelta = width - overlap;
        int heightDelta = height - overlap;

        top.setBounds(x, y, width, height);
        middle.setBounds(x + widthDelta, y + heightDelta,
            width, height);
        bottom.setBounds(x + (widthDelta) * 2, y +
            (heightDelta) * 2, width, height);

        JPanel contentPane = new JPanel() {
            public boolean isOptimizedDrawingEnabled() {
                return false;
            }
        };
        contentPane.setLayout(null);
        contentPane.add(top);
        contentPane.add(middle);
        contentPane.add(bottom);

        contentPane.setComponentZOrder(top, 0);
        contentPane.setComponentZOrder(middle, 1);
        contentPane.setComponentZOrder(bottom, 2);
        ///*
        contentPane.setComponentZOrder(top, 2);
        contentPane.setComponentZOrder(middle, 1);
        contentPane.setComponentZOrder(bottom, 0);
        //*/

        frame.setContentPane(contentPane);
        frame.setSize(300, 200);
        frame.setVisible(true);
      }
    });
  }
}
